package GUI.TabPanels;

import java.awt.Color;

import javax.swing.JPanel;

import GUI.AddBooking.AddBookingPanel;
import GUI.AddBooking.ViewAvailableRoomsPanel;
import GUI.AddBooking.ViewBookingPanel;

@SuppressWarnings("serial")
public class BookingPanel extends JPanel{
	private static BookingPanel instance = null;
	public static AddBookingPanel add_booking_panel;
	public static ViewBookingPanel view_booking_panel;
	public static ViewAvailableRoomsPanel view_rooms_panel;

	private BookingPanel(){
		 this.setBackground(new Color(147, 37, 37));
	}

	public static BookingPanel getInstance(){
		if(instance == null){
			instance = new BookingPanel();
			InitializePanels();
		}
		return instance;
	}
	
	private static void InitializePanels(){
		add_booking_panel = new AddBookingPanel();
		view_booking_panel = new ViewBookingPanel();
		view_rooms_panel = new ViewAvailableRoomsPanel();
		instance.add(view_booking_panel);
	}

	public void ViewBookings(){
		this.remove(view_rooms_panel);
		this.remove(add_booking_panel);
		view_booking_panel.Update();
		this.add(view_booking_panel);
		this.paint(getGraphics());
		this.setVisible(false);
		this.setVisible(true);
		
	}

	public void AddBookings(){
		this.remove(view_booking_panel);
		this.remove(view_rooms_panel);
		this.add(add_booking_panel);	
		this.paint(getGraphics());
		this.setVisible(false);
		this.setVisible(true);
	}
	
	public void ViewRooms(){
		this.remove(add_booking_panel);
		this.add(view_rooms_panel);
		view_rooms_panel.Update();
		this.paint(getGraphics());
		this.setVisible(false);
		this.setVisible(true);
	}
	
	public String[] getBookingDates(){
		String[] booking_info = add_booking_panel.getBookingDates();
		return booking_info;
	}
	
	public void UpdateAvailableRooms() {
		view_rooms_panel.Update();
		this.setVisible(false);
		this.setVisible(true);
	}


	// input[0] -> hotelID
	// input[1] -> start_date
	// input[2] -> end_date
	public String[] getAvailableRoomsInfo() {
		String[] booking_dates = getBookingDates();
		String[] results = {add_booking_panel.getHotelID(), booking_dates[0], booking_dates[1]};
		return results;
	}
	
	public String[] getCustomerID(){
		String[] fields = add_booking_panel.getCustomerID();
		return fields;
	}

	public void UpdateBookings() {
		view_booking_panel.UpdateTable();		
	}
}
